package com.xxy.partnermatch.easyExcel;

import com.alibaba.excel.EasyExcel;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * ClassName: ImportXingQiuUser
 * Package: com.xxy.partnermatch.easyExcel
 * Description: 导入星球用户到数据库
 *
 * @Author 十一
 * @Create 2024/11/18 10:44
 * @Version 1.0
 */
public class ImportXingQiuUser {

    public static void main(String[] args) {
        // 1. 确定文件路径: Excel数据文件放在自己电脑上，能够找到的路径
        String fileName = "D:\\studyNote\\Java\\project\\伙伴匹配项目\\partnerMatch\\src\\main\\resources\\testExcel.xlsx";
        // 2. 这里需要指定 用哪个class去读, 然后读取第一个sheet, 同步读取会自动 finish
        List<XingQiuTableUserInfo> userInfoList =
                EasyExcel.read(fileName).head(XingQiuTableUserInfo.class).sheet().doReadSync();
        System.out.println("总数: " + userInfoList.size());
        Map<String, List<XingQiuTableUserInfo>> map = userInfoList.stream()
                .filter(userInfo -> StringUtils.isNoneEmpty(userInfo.getUsername()))
                .collect(Collectors.groupingBy(XingQiuTableUserInfo::getUsername));
        for (Map.Entry<String, List<XingQiuTableUserInfo>> entry : map.entrySet()) {
            // map: {"xuxuanya": 3, "bailu": 2, "liyitong": 2}
            if (entry.getValue().size() > 1) {
                System.out.println("username: " + entry.getKey());
            }
        }
        System.out.println("不重复昵称数: " + map.keySet().size());
    }

}
